﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcDemoApp.Models;

namespace MvcDemoApp.Controllers
{
    public class DemoController : Controller
    {
        //
        // GET: /Demo/

        public ActionResult Index()
        {
            return View(new Person());
        }

        [HttpPost]
        public ActionResult Save(Person p)
        {
            return View("Index", p);
        }

        public ActionResult SetLanguage(string language)
        {
            Session["SelectedCultureId"] = language;
            return RedirectToAction("Index");
        }

       

        protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            string culture = (string)requestContext.HttpContext.Session["SelectedCultureId"];
            if (culture != null)
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(culture);
                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(culture);
            }
            base.Initialize(requestContext);
        }

       

    }
}
